
<script>
export default {
  props: ["element", "data", "index"],
  data() {
    return {};
  },
  // eslint-disable-next-line no-unused-vars
  render(h) {
    return (
      <drop-wrap data={this.data} index={this.index} element={this.element}>
        <el-button
          nativeOn={this.onEvent}
          style={this.style}
          type={this.element.options.type}
        >
          {this.element.options.name}
        </el-button>
      </drop-wrap>
    );
  },
  methods: {
    confirm(func) {
      let _this = this;

      return function () {
        let confirmOption = _this.element.options.confirmOption;
        if (_this.element.options.isConfirm) {
          _this
            .$confirm(confirmOption.content, confirmOption.title, {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: confirmOption.type,
            })
            .then(() => {
              func.call(_this);
              _this.$message({
                type: "success",
                message: "成功",
              });
            })
            .catch(() => {
              _this.$message({
                type: "info",
                message: "取消",
              });
            });
        } else {
          func.call(_this);
        }
      };
    },
    exec() {

      if (this.element.options.isSubmit) {
        this.store.eventCenter.fire(
          "submit",
          this.store.models
        );
      }
      this.store.proxy;
      this.element.options.eventCode &&
        this.store.eventCenter
          .fire(this.element.options.eventCode, {
            triggerSource: this.element,
          })
          .then(() => {
                  if (this.element.options.dialogKey) {
                    this.store.openDialog(
                      this.element.options.dialogKey,
                      this.element.key,
                    );
                  }
          });

      if (!this.element.options.eventCode&&this.element.options.dialogKey) {
        this.store.openDialog(
          this.element.options.dialogKey,
          this.element.key,
          { sss: "xxx" }
        );
      }
    },
  },
  computed: {
    style() {
      return {
        transform: this.element.options.transform
          ? `translate(${this.element.options.transform.x}px, ${this.element.options.transform.y}px)`
          : null,
      };
    },
    store() {
      return this.element.getRoot();
    },
    onEvent() {
      return this.element.key
        ? {
            [this.element.options.triggerType]: this.confirm(this.exec),
          }
        : null;
    },
  },
  mounted() {
    // console.log('this',this)
  },
};
</script>

<style scoped>
</style>